package com.itheima.controller;

import com.alibaba.fastjson.JSON;
import com.itheima.service.SysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/sysDictData")
public class SysDictDataController {

    @Autowired
    private SysDictDataService sysDictDataService;

    /**
     *
     * 根据字典类型数组获取字典数据
     * @param dictType
     * @return
     */
    @PostMapping("/getListByDictType")
    public String getListByDictType(@RequestParam("/dictType") String dictType){
        List<Map> listByDictType = sysDictDataService.getListByDictType(dictType);
        HashMap map = new HashMap();
        HashMap map2 = new HashMap();
        map.put("code","success");
        map2.put("defaultValue",1);
        map2.put("list",listByDictType);
        map.put("data",map2);

        return JSON.toJSONString(map);
    }

    /**
     * 根据字典类型数组获取字典数据
     */
    @PostMapping("/getListByDictTypeList")
    public String getListByDictTypeList(@RequestBody() String[] dictTypeList){
        List<Map> listByDictTypeList = sysDictDataService.getListByDictTypeList(dictTypeList);
        HashMap map1 = new HashMap();
        HashMap map2 = new HashMap();
        HashMap map3 = new HashMap();
        map3.put("list",listByDictTypeList);
        map2.put("sys_account_source",map2);
        map1.put("code","success");
        map1.put("data",map2);
        return JSON.toJSONString(map1);
    }
}


